<template>
  <div>测试消息订阅</div>
</template>

<script>
import pubsub from "pubsub-js";

export default {
  methods: {
    demo(msgName, data) {
      console.log("我是School组件，收到了数据：", msgName, data);
    },
  },
  mounted() {
    // 订阅消息
    pubsub.subscribe("demo", this.demo);
  },
  beforeDestroy() {
    // 取消订阅
    pubsub.unsubscribe("demo");
  }
};
</script>

<style  scoped>
</style>